/**
 * Project Name:HomeActivity
 * Date:2016-3-3下午7:24:41
 * Copyright (c) 2016, askzhao All Rights Reserved.
 *
 */
package com.kkd.kkdapp.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewParent;
import android.webkit.WebView;

/**
 * ClassName: KKdWebview <br/>
 * date: 2016-3-3 下午7:24:41 <br/>
 *
 * @author askzhao
 * @version 
 */
public class KKdWebview extends WebView{


	/**
	 * @param context
	 * @param attrs
	 * @param defStyle
	 */
	public KKdWebview(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param context
	 * @param attrs
	 */
	public KKdWebview(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param context
	 */
	public KKdWebview(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	float dertaY = 0;
	float lastY = 0;
	float dertaX = 0;
	float lastX = 0;
	/* (non-Javadoc)
	 * 避免父控件拦截touch事件
	 */
	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		
		switch (ev.getAction()) {
		case MotionEvent.ACTION_DOWN:
			dertaY = 0;
			lastY = ev.getY();
			dertaX = 0;
			lastX = ev.getX();
			break;
		case MotionEvent.ACTION_MOVE:
			dertaY = ev.getY() - lastY;
			dertaX = ev.getX() - lastX;
			lastX = ev.getX();
			lastY = ev.getY();
			break;
		default:
			break;
		}
		
		if(Math.abs(dertaX)>Math.abs(dertaY)){
			ViewParent parent = getParent();
			while(parent!=null){
				parent.requestDisallowInterceptTouchEvent(true);
				parent = parent.getParent();
			}
		}
		return super.dispatchTouchEvent(ev);
	}

}
